﻿using System.Collections.Generic;
using UnityEngine;

public class VerticalCollate : ICollateStrategy
{
    nLayerOrder _StartOrder = nLayerOrder.Null;

    public void OBOrder(nLayerOrder startOrder, ObjectBase ob)
    {

    }


    public void ReOrder(nLayerOrder startOrder, ref List<ObjectBase> unitobjects)
    {
        _StartOrder = startOrder;

        if (_StartOrder == nLayerOrder.Null)
        {

            Debug.LogError("VerticalCollate.ReOrder ");

            return;
        }

        unitobjects.Sort(new BaseObjectCompare());

        int starto = (int)_StartOrder;

        //  先按照Y排序
        for (int i = 0; i < unitobjects.Count; ++i)
        {
            unitobjects[i].SetSortingOrder(starto--);
        }
    }

    class BaseObjectCompare : IComparer<ObjectBase>
    {
        public int Compare(ObjectBase a, ObjectBase b)
        {
            return a._WorldPos.y.CompareTo(b._WorldPos.y);
        }
    }

}
